package 斗地主;

import javax.swing.*;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class Poker extends JLabel {
    private String name;
    private boolean tf;
    private boolean click=false;
    private boolean clicked=false;

    public Poker(String name, boolean tf) {
        this.name = name;
        this.tf = tf;
        if (this.tf)
            images(name);
        else
            ture();
        this.setSize(0,0);
        this.setVisible(true);
       this.addMouseListener(new MouseListener() {
           @Override
           public void mouseClicked(MouseEvent e) {
               if (click){
                   int flag = 0;
                   if (clicked){
                       flag = 20;
                   }
                   else {
                       flag = -20;
                   }
                   clicked = !clicked;
                   Point point1 = Poker.super.getLocation();
                   Poker.super.setLocation(point1.x,point1.y+flag);
               }
           }

           @Override
           public void mousePressed(MouseEvent e) {

           }

           @Override
           public void mouseReleased(MouseEvent e) {

           }

           @Override
           public void mouseEntered(MouseEvent e) {

           }

           @Override
           public void mouseExited(MouseEvent e) {

           }
       });
    }
    public void images(String name){
        this.setIcon(new ImageIcon());
        this.click=true;
    }
    public void ture(){
        this.setIcon(new ImageIcon());
    }
}
